package com.green.service.manage.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.green.dao.manage.AreaPermissionDao;
import com.green.model.manage.Area;
import com.green.model.manage.AreaPermission;
import com.green.model.manage.Person;
import com.green.service.common.ServiceContext;
import com.green.service.common.impl.BaseServiceImpl;
import com.green.service.manage.AreaPermissionService;



/**
 * 人员
 * 
 */
@Repository("areaPermissionService")
public class AreaPermissionServiceImpl extends BaseServiceImpl implements AreaPermissionService {
	@Autowired
	private AreaPermissionDao areaPermissionDao;
	@Override
	public int insertAreaPermission(AreaPermission ct) {
		return areaPermissionDao.insertAreaPermission(ct);
	}

	@Override
	public int updateAreaPermission(AreaPermission ct) {
		return areaPermissionDao.updateAreaPermission(ct);
	}

	@Override
	public int deleteAreaPermission(Map<String, Object> param) {
		return areaPermissionDao.deleteAreaPermission(param);
	}

	@Override
	public AreaPermission getAreaPermissionById(String id) {
		return areaPermissionDao.getAreaPermissionById(id);
	}

	@Override
	public List<AreaPermission> getAreaPermissionList(Map<String, Object> param) {
		return areaPermissionDao.getAreaPermissionList(param);
	}

	@Override
	public List<AreaPermission> getAreaPersonById(Map<String, Object> param) {
		return areaPermissionDao.getAreaPersonById(param);
	}

	@Override
	public int saveAreaPermission(String personId,String ids,String cityName) {
		//先删除  在添加
		if(null!=personId&&!personId.equals("")){
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("personId", personId);
		this.deleteAreaPermission(param);
	    }
		
		int count = 0;
		if (null != ids) {
			String[] idList = ids.split(",");
			for (String obj : idList) {
				Area area=new Area();
				area.setId(obj);
				Person person =new Person();
				person.setId(personId);
				AreaPermission areaPermission=new AreaPermission();
				areaPermission.setCreateBy(ServiceContext.getLoginPerson());
				areaPermission.setId(UUID.randomUUID().toString());
				areaPermission.setArea(area);
				areaPermission.setCityName(cityName);
				areaPermission.setPerson(person);
				count=this.insertAreaPermission(areaPermission);
			}
		}else{
			count=0;
		}
		return count;
	}
	
	
}
